﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!--[if IE 8]> <html lang="zh" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="zh" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="zh">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta content="width=device-width, initial-scale=1" name="viewport" />
        <meta content="" name="description" />
        <meta content="" name="author" />
        <link type="text/css" rel="stylesheet" media="all" href="styles/global.css" />
        <link type="text/css" rel="stylesheet" media="all" href="styles/global_color.css" />
        <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
        <script src="styles/js/tools.js"></script>
        <script src="styles/plugins/layer/layer.js"></script>
    </head>
    <body class="index">
        <div class="login_box">
            <form  action="/login/manager" method="post" id="loginForm">

            <table>
                <tr>
                    <td class="login_info">账号：</td>
                    <td colspan="2"><input name="userName" type="text" class="width150" /></td>
                    <td class="login_error_info"><span class="required">30长度的字母、数字和下划线</span></td>
                </tr>
                <tr>
                    <td class="login_info">密码：</td>
                    <td colspan="2"><input name="password" type="password" class="width150" /></td>
                    <td><span class="required">30长度的字母、数字和下划线</span></td>
                </tr>
                <tr>
                    <td></td>
                    <td class="login_button" colspan="2">
                        <a href="" onclick="loginForm()">
                            <img src="images/login_btn.png" /></a>
                    </td>    
                    <td><span class="required">用户名或密码错误，请重试</span></td>                
                </tr>
            </table>
            </form>
        </div>
    <script>

        $(document).ready(function () {
            console.log("请先登陆。")
        });

        /**
         * 登陆
         * @returns {boolean}
         */
        function loginForm() {

            var param = tools.formParams("loginForm")

            var userName = param["userName"];
            var password = param["password"];
            var remember = param["remember"];

            //验证
            if (userName.trim() == "") {
                layer.msg("请输入用户名",{icon:2});
                return false;
            }
            if (password.trim() == "") {
                layer.msg("请输入密码",{icon:2});
                return false;
            }

            //开始登陆样式
            $("#login_btn_ico").attr("class", "fa fa-spinner fa-spin");
            $.ajax({
                type : "post",
                url : "/login/manager",
                data : {"userName":userName,"password":getPassword(password),"remember":remember},
                dataType : "json",
                success : function(data){

                    if (data.success) {
                        layer.msg('登陆成功！',{icon: 1,time:1000}, function(){
                            window.location.href = "/";
                        });

                    } else {
                        $("#login_btn_ico").attr("class", "fa fa-arrow-circle-right");
                        $("#password").val("");
                        var _case = {
                            16: "没有此用户。",
                            11: "密码错误！",
                            14: "服务器拒绝登陆！"
                        };
                        tools.errorTip(_case, data.code);
                    }
                }
            });
        }

        function getPassword(password){
            var pwdMd5 = "";
            $.ajax({
                type : "post",
                url : "/login/md5",
                data : {pwd:password},
                async : false,
                success : function(data){
                    pwdMd5 = data;
                }
            });
            return pwdMd5;
        }


        //绑定回车事件
        $(document).keydown(function (event) {
            if (event.keyCode == 13) {
                loginForm();
            }
        });

    </script>
    </body>
</html>
